package com.fms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fms.entity.OutboundOrder;
import com.fms.entity.WarehouseBoard;
import com.fms.mapper.OutboundOrderMapper;
import com.fms.mapper.WarehouseBoardMapper;
import com.fms.service.WarehouseBoardService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@RequiredArgsConstructor
public class WarehouseBoardServiceImpl extends ServiceImpl<WarehouseBoardMapper, WarehouseBoard> implements WarehouseBoardService {

    private final WarehouseBoardMapper warehouseBoardMapper;

    private final OutboundOrderMapper outboundOrderMapper;

    //仓库板子信息
    @Override
    public List<WarehouseBoard> getAllBoard() {
        LambdaQueryWrapper<WarehouseBoard> queryWrapper = new LambdaQueryWrapper<>();
        List<WarehouseBoard> warehouseBoards = warehouseBoardMapper.selectList(queryWrapper);
        return warehouseBoards;
    }

    @Override
    public List<WarehouseBoard> getOutboundBoardByOrderId(Long orderId) {
        LambdaQueryWrapper<OutboundOrder> outWrapper = new LambdaQueryWrapper<>();
        outWrapper.eq(OutboundOrder::getOrderId, orderId);
        List<OutboundOrder> outboundOrders = outboundOrderMapper.selectList(outWrapper);
        List<WarehouseBoard> warehouseBoards = new ArrayList<WarehouseBoard>();
        if (outboundOrders!=null) {
            for (OutboundOrder outboundOrder : outboundOrders){
                if ("板子".equals(outboundOrder.getMaterialType())){
                    WarehouseBoard board = warehouseBoardMapper.selectById(outboundOrder.getMaterialId());
                    board.setBoardAddAmount(outboundOrder.getAddBoardAmount());
                    warehouseBoards.add(board);
                }
            }
        }
        return warehouseBoards;
    }
}
